#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
typedef pair<int,int> PLL;
int a[N];
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
	//	PLL b[n+1];
	    vector<PLL>b (n+1);
		for (int i = 1; i <= n; i ++) {
			cin >> a[i];
		}
		for (int i = 1; i <= n; i ++) {
			cin >> b[i].first;
			b[i].second = i;
		}
		int ans = 0x3f3f3f3f;
		for (int i = 1; i <= n; i ++) {
			int j = 1;
			while(b[j].first < a[i]) j ++;
		//	cout << y << endl;
			ans = min(ans, i - 1 + j - 1);
		}
		cout << ans << '\n';
	}
}
